﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using VideoClassLibrary.BusinessLogicLayer;
public partial class AdminUpdatePWD : AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
  
    // MD5加密
    public static string MD5Enctrypt(string pwd)
    {
        return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5");
    }
    protected void btupdate_Click(object sender, EventArgs e)
    {
        // 确认修改
        AdminModule ac = new AdminModule();
        //HttpCookie coo = Request.Cookies["Admin"];
        //int id=Convert.ToInt32(coo.Values["ID"]);
        //string oldpwd=coo.Values["pwd"];
        int id = this.CurrentUser.ID;
        string oldpwd = this.CurrentUser.VA_password;
        string adminpwd = txtoldpwd.Text.Trim();
        string MDadminpwd = MD5Enctrypt(adminpwd);
        string newpwd = txtpwd.Text.Trim();
        //if (coo != null)
        //{
        if (oldpwd == MDadminpwd)
        {
            int result = ac.UpdatePwd(newpwd, id);
            if (result == 1)
            {
                PageHelper.AlterMsg("修改密码成功");
                czupdate_Click(sender, e);
            }
            else
            {
                Label1.Text = "修改密码失败";
            }
        }
        else
        {
            Label1.Text = "原始密码不正确";
        }
        //}
        //else
        //{
        //    Label1.Text = "还未登录不能修改";
        //}
        
        
    }
    protected void czupdate_Click(object sender, EventArgs e)
    {
       // 重置修改信息
        txtoldpwd.Text = null;
        txtpwd.Text = null;
        txtagain.Text= null;

    }

}
